package cn.wizzer.app.web.modules.controllers.user;


import cn.wizzer.app.user.modules.services.GoodsService;
import cn.wizzer.framework.filter.ParamFilter;
import cn.wizzer.framework.util.Result;
import cn.wizzer.framework.util.param.ParamVerify;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

@IocBean
@At("/api/user/goods")
public class ApiUserGoodsController {
    @Inject
    @Reference
    private GoodsService goodsService;

    /**
     * 商品列表(分页)
     *
     * @param language   String
     * @param pageNumber int
     * @param pageSize   int
     * @return Object
     */
    @At
    @Ok("json:{locked:'version|asBanner|disabled|ctAt|opAt',ignoreNull:true}")
    @Filters({@By(type = ParamFilter.class)})
    public Object list(@ParamVerify(required = true, name = "language") String language,
                       @ParamVerify(required = true, name = "pageNumber") int pageNumber,
                       @ParamVerify(required = true, name = "pageSize") int pageSize) {
        return Result.success().addData(goodsService.listPage(pageNumber, pageSize, language, null, false));
    }

    /**
     * 商品详情
     *
     * @param id
     * @return
     */
    @At
    @Ok("json")
    @Filters({@By(type = ParamFilter.class)})
    public Object detail(@ParamVerify(required = true, name = "id") String id) {
        return Result.success().addData(goodsService.fetch(id));
    }

    /**
     * 轮播图
     *
     * @return
     */
    @At
    @Ok("json:{locked:'stock|disabled|version|asBanner',ignoreNull:true}")
    @Filters({@By(type = ParamFilter.class)})
    public Object banner(@ParamVerify(required = true) String language) {
        return Result.success().addData(goodsService.queryByLanguage(language));
    }
}
